package com.example.cinema.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.example.cinema.BR;
import com.example.cinema.bindingdata.UserMassageItemData;

import java.util.List;

//用户消息选中弹窗消息列表适配器
public class UserMasgItemAdapter<T>  extends BaseAdapter {

    private LayoutInflater inflater;
    private List<T> data;
    private int layoutid;

    public UserMasgItemAdapter(Context context, List<T> data,int layid) {
        this.inflater = LayoutInflater.from(context);
        this.data = data;
        this.layoutid = layid;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private ViewDataBinding viewDataBinding;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView ==null)
        {
            viewDataBinding = DataBindingUtil.inflate(inflater,layoutid,parent,false);
            convertView = viewDataBinding.getRoot();
        }
        viewDataBinding.setVariable(BR.umitemdata,data.get(position));

        return convertView;
    }
}
